package com.ruoyi.web.controller.cs;

import java.util.List;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BasicsController;
import com.ruoyi.common.core.domain.Response;
import com.ruoyi.common.core.page.ResponsePageInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.cs.domain.vo.TBoxVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cs.domain.TBoxTitle;
import com.ruoyi.cs.service.ITBoxTitleService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 箱子标题Controller
 * 
 * @author ruoyi
 * @date 2021-03-25
 */

@Api(tags = {"箱子标题管理"})
@RestController
@RequestMapping("/cs/boxtitle")
@SuppressWarnings("all")
public class TBoxTitleController extends BasicsController
{
    @Autowired
    private ITBoxTitleService tBoxTitleService;

    /**
     * 后台查询箱子标题列表
     */
    @ApiOperation("后台查询箱子标题列表")
    @RequestMapping(name="后台查询箱子标题列表",value="listBack",method = RequestMethod.POST)
    public ResponsePageInfo<TBoxTitle> listBack(@RequestBody  TBoxTitle tBoxTitle)
    {
        startPage(tBoxTitle.getPageNum(),tBoxTitle.getPageSize());
        tBoxTitle.setBackStage(Constants.BACKSTAGE);
        List<TBoxTitle> list = tBoxTitleService.selectTBoxTitleList(tBoxTitle);
        return toResponsePageInfo(list);
    }

    /**
     * 新增箱子标题
     */
    @PreAuthorize("@ss.hasPermi('cs:boxtitle:add')")
    @ApiOperation("新增箱子标题")
    @RequestMapping(name="新增箱子标题",value="add",method = RequestMethod.POST)
    @Log(title = "箱子标题", businessType = BusinessType.INSERT)
    public Response<Integer> add(@RequestBody TBoxTitle tBoxTitle)
    {
        return toResponse(tBoxTitleService.insertTBoxTitle(tBoxTitle));
    }

    /**
     * 修改箱子标题
     */
    @PreAuthorize("@ss.hasPermi('cs:boxtitle:edit')")
    @ApiOperation("修改箱子标题")
    @RequestMapping(name="修改箱子标题",value="edit",method = RequestMethod.POST)
    @Log(title = "箱子标题", businessType = BusinessType.UPDATE)
    public Response<Integer> edit(@RequestBody TBoxTitle tBoxTitle)
    {
        return toResponse(tBoxTitleService.updateTBoxTitle(tBoxTitle));
    }

    /**
     * 删除箱子标题
     */
    @PreAuthorize("@ss.hasPermi('cs:boxtitle:remove')")
    @ApiOperation("删除箱子标题")
    @RequestMapping(name="删除箱子标题",value="remove",method = RequestMethod.GET)
    @Log(title = "箱子标题", businessType = BusinessType.DELETE)
    @ApiImplicitParam(name = "boxtitleIds",value = "需要删除的箱子标题ID,多个以“,”分割" , dataType = "String", paramType = "query", required = false)
    public Response<Integer> remove(String boxtitleIds)
    {
        if (StringUtils.isNotEmpty(boxtitleIds)) {
            String[] ids = boxtitleIds.split(",");
            int row = tBoxTitleService.deleteTBoxTitleByIds(ids);
            if (row == Constants.FAILCODE) {
                return Response.fail(Constants.FAILCODE,"选中箱子标签下存在对应的箱子，请先删除箱子!");
            }else {
                return  toResponse(row);
            }
        }else{
            return Response.fail(Constants.FAILCODE,"参数不能为空!");
        }
    }
//    /**
//     * 停用箱子标题
//     */
//    //@PreAuthorize("@ss.hasPermi('cs:boxtitle:remove')")
//    @ApiOperation("停用箱子标题")
//    @RequestMapping(name="停用箱子标题",value="stop",method = RequestMethod.GET)
//    @Log(title = "箱子标题", businessType = BusinessType.STOP)
//    public AjaxResult stop(String boxtitleIds)
//    {
//        if (StringUtils.isNotEmpty(boxtitleIds)) {
//            String[] ids = boxtitleIds.split(",");
//            int row = tBoxTitleService.batchStopTBoxTitle(ids);
//            if (row == Constants.FAILCODE) {
//                return  new AjaxResult(Constants.FAILCODE,"选中箱子标签下存在可用箱子，请先停用箱子!");
//            }else {
//                return  toAjax(row);
//            }
//        }else{
//            return new AjaxResult(Constants.FAILCODE,"参数不能为空!");
//        }
//    }
//    /**
//     * 启用箱子标题
//     */
//    //@PreAuthorize("@ss.hasPermi('cs:boxtitle:remove')")
//    @ApiOperation("启用箱子标题")
//    @RequestMapping(name="启用箱子标题",value="enable",method = RequestMethod.GET)
//    @Log(title = "箱子标题", businessType = BusinessType.ENABLE)
//    public AjaxResult enable(String boxtitleIds)
//    {
//        if (StringUtils.isNotEmpty(boxtitleIds)) {
//            /**如何情况下都能启用箱子标签*/
//            String[] ids = boxtitleIds.split(",");
//            return  toAjax(tBoxTitleService.batchEnableTBoxTitle(ids));
//        }else{
//            return new AjaxResult(Constants.FAILCODE,"参数不能为空!");
//        }
//    }

    /**--------------------------------------------前端接口------------------------------*/
    /**
     * 查询箱子标题列表
     */
    @ApiOperation("web端查询箱子标题列表")
    @RequestMapping(name="查询箱子标题列表",value="common/list",method = RequestMethod.GET)
    public Response<List<TBoxTitle>> list(String titleType)
    {
        TBoxTitle tBoxTitle = new TBoxTitle();
        tBoxTitle.setDelFlag(Constants.SUCCESS);
        tBoxTitle.setTitleType(titleType);
        List<TBoxTitle> list = tBoxTitleService.selectTBoxTitleList(tBoxTitle);
        return Response.success(list);
    }
}
